package com.wu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wu.mapper.LabelsMapper;
import com.wu.pojo.Labels;
import com.wu.pojo.model.UserToken;
import com.wu.service.LabelsService;
import com.wu.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author: 吴磊
 * @program: blog
 * @create: 2021-04-19 20:28
 */
@Service
public class LabelsServiceImpl extends ServiceImpl<LabelsMapper, Labels> implements LabelsService {

    @Autowired
    private LabelsMapper labelsMapper;

    @Autowired
    private TokenUtils tokenUtils;

    @Override
    public List<Labels> getAllLabels() {
        return labelsMapper.getAllLabels();
    }

    /**
     * 获取用户所有的标签
     *
     * @return
     */
    @Override
    public List<Labels> getAllUserLabels(String user_id) {
        List<Labels> allUserLabels = null;
        if (StringUtils.isEmpty(user_id)) {
            UserToken userToken = tokenUtils.parseTokenToUserToken();
            String userId = userToken.getUserId();
            allUserLabels = labelsMapper.getAllUserLabels(userId);
        } else {
            allUserLabels = labelsMapper.getAllUserLabels(user_id);
        }
        return allUserLabels;
    }
}
